package com.example.boot50.controller;

import com.example.boot50.entity.Product;
import com.example.boot50.mapper.ProductMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wxd
 * @version 1.0
 */
@RestController
public class ProductController {
    final
    ProductMapper mapper;

    public ProductController(ProductMapper mapper) {
        this.mapper = mapper;
    }

    @RequestMapping("/insert")
    public void insert(@RequestBody Product product) {
        mapper.insert(product);
    }

    @RequestMapping("/select")
    public List<Product> select() {
        return mapper.select();
    }

    @RequestMapping("/deleteById")
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @RequestMapping("/selectById")
    public Product selectById(int id) {
        return mapper.selectById(id);
    }

    @RequestMapping("/update")
    public void update(@RequestBody Product product) {
        mapper.update(product);
    }
}
